package cn.jingyinghui.config;

import cn.jingyinghui.handler.ChatHandler;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket // 开启对讲机功能
public class WebSocketConfig implements WebSocketConfigurer {

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 设置一个叫"/chat"的频道，菜农们用这个频道通话
        registry.addHandler(new ChatHandler(), "/chat")
                .setAllowedOrigins("*"); // 允许所有人连接
    }
}